using System;
using System.Collections.Generic;
using System.IO;
using IronMis2.Models;
using NHibernate.Expression;
using Castle.MonoRail.Framework;
using Castle.ActiveRecord.Framework.Validators;


namespace IronMis2.Controllers
{
    public class PayoutController : BaseController
    {
        public void Pay_out()
        {
            PropertyBag["payouts"] = Payout.FindAll();
        }
        
        public void ModifyPayout(Guid id)
        {
            PropertyBag["payout"] = Payout.Find(id);
            PropertyBag["departments"] = Department.FindAll();
            PropertyBag["employees"] = Employee.FindAll();
            RenderView("PayoutDetail");
        }
        public void  DetailItem(Guid id)
        {
            PropertyBag["payout"] = Payout.Find(id);
            RenderView("PayoutItems");
        }

        public void PayoutSave([DataBind("payout")] Payout payout)
        {
            payout.UpdateAndFlush();
            RedirectToAction("Pay_out");
        }
        public void  PayoutAdd()
        {
            PropertyBag["employees"] = Employee.FindAll();
            PropertyBag["departments"] = Department.FindAll();
        }
        public void PayoutNew([DataBind("payout")] Payout payout)
        {
            payout.CreateAndFlush();
            RedirectToAction("Pay_out");
        }
        public  void PayoutDelete(Guid id)
        {
           // Payout.Find(id).DeleteAndFlush();
            RedirectToAction("Pay_out");
        }

        public void ItemEdit(Guid id)
        {
            PropertyBag["item"] = Item.Find(id);
            PropertyBag["payouts"] = Payout.FindAll();
            RenderView("ItemDetail");
        }
        public void ItemSave([DataBind("item")] Item item)
        {
            item.UpdateAndFlush();
            PropertyBag["payout"] =Payout.Find(item.Payout.Id);
            
            RenderView("PayoutItems");
        }
        public void ItemAdd(Guid id)
        {
            PropertyBag["payout"] = Payout.Find(id);
        }
        public void ItemNew([DataBind("item")] Item item)
        {
            item.CreateAndFlush();
            PropertyBag["payout"] = Payout.Find(item.Payout.Id);

            RenderView("PayoutItems");
        }
        public void ItemDelete(Guid id)
        {
            PropertyBag["payout"] = Item.Find(id).Payout;
            Item.Find(id).DeleteAndFlush();
            RenderView("PayoutItems");
        }
    }
}
